package com.bdqn.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.springbootweb.mapper.SysUserMapper;
import com.bdqn.springbootweb.pojo.SysUser;
import com.bdqn.springbootweb.service.SysUserService;
import com.sun.istack.internal.logging.Logger;
import org.apache.catalina.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @RequestMapping("/login")
    public String login(Model model, HttpSession session, @RequestParam String usrName, @RequestParam String usrPassword) {
        System.out.println(usrName + "," + usrPassword);
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("usr_name", usrName);
        queryWrapper.eq("usr_password", usrPassword);
        SysUser sysUser = sysUserService.getOne(queryWrapper);
        if (sysUser != null) {
            System.out.println("登录成功");
            model.addAttribute("loginUser", sysUser);
            return "main";
        }else {
            session.setAttribute("msg","用户名或密码错误,登录失败");
            return "forward:/login.jsp";
        }
    }

    @RequestMapping("/main")
    public String main(){
        return "/main";
    }

}
